$(function() {
	$.ajax({
		type: "get",
		url: "{$static_dir}/assets/json/anomaly.json",
		success: function(res) {
			if(typeof res=='string'){
				console.log(1)
				var res = JSON.parse(res).data;
			}else{
				var res = res.data;
			}
			
			console.log(res[0].earlyWarningtime);
			var tablebody;

			for(var i = 0; i < res.length; i++) {
				if(res[i].status == 1) {
					td = `<div class="tpl-table-black-operation">
						<a class='dispose'>
							<i class="am-icon-pencil"></i> 处理
						</a>
					</div>`;
				} else {
					td = res[i].statusmain;
				}
				tablebody += `
					<tr>
						<td>${res[i].earlyWarningtime}</td>
						<td>${res[i].order_no}</td>
						<td>${res[i].number}</td>
						<td>${res[i].driver_name}</td>
						<td>${res[i].anomaly_type_name}</td>
						<td>${td}</td>
					</tr>
				`
			};
			$('tbody').html(tablebody);
			$('.dispose').on('click', function() {
				var that = this;
				var idx=$(this).closest('tr').index();
				console.log(idx)
				layer.prompt({
					title: '请输入处理理由',
					formType: 3
				}, function(pass, index) {
					console.log(res);
					$(that).closest('td').html(pass);
					res[idx].statusmain=pass;
					res[idx].status=2;
					
					var strbody = "";
					var wid = 0;
					for(var i = 0; i < res.length; i++) {
						if(res[i].status == 1) {
							if(res[i].anomaly_type == 1) {
								strbody += `<li style="float: left;padding-left:50px ;color:red">司机目的地偏离预警（订单${res[i].order_no}，司机${res[i].driver_name}出现目的地偏离）</li>`
							} else if(res[i].anomaly_type == 2) {
								strbody += `<li style="float: left;padding-left:50px;color:red">司机出发地偏离预警（订单${res[i].order_no}，司机${res[i].driver_name}出发目的地偏离）</li>`
							} else if(res[i].anomaly_type == 3) {
								strbody += `<li style="float: left;padding-left:50px;color:red">订单轨迹偏离预警（订单${res[i].order_no}，车辆行驶过程中出现轨迹偏离）</li>`
							} else if(res[i].anomaly_type == 4) {
								strbody += `<li style="float: left;padding-left:50px;color:red">订单超时预警（订单${res[i].order_no}，行驶时间过长）</li>`
							} else if(res[i].anomaly_type == 5) {
								strbody += `<li style="float: left;padding-left:50px;color:red">空车移动预警（车辆${res[i].order_no}出现空车移动）</li>`
							}
						} else {

						}
					}
					
					parent.$('.str3 ul').html("")
					parent.$('.str3 ul').html(strbody)
					console.log(parent.$('.str3 ul'))
					
					for(var j = 0; j < parent.$('.str3 ul li').length/3; j++) {
						console.log(wid)
						var num = parent.$('.str3 ul li').eq(j).width() - 0;
						wid += num;
					}
					console.log(wid)
					wid += parent.$('.str3 ul li').length * 80;
					console.log(wid)
					parent.$('.str3 ul').css('width', wid);
					parent.$('.str3 ul').css('left', 0);
					layer.close(index);
				});
			})
		}

	});
})